<?php

namespace App\Models;

class Service extends Base
{
    protected $fillable = [
        'type', 'title', 'price', 'is_special', 'special_price', 'service_merchant', 'image_file', 'video_file'
        ,'audio_file', 'desc', 'sort', 'unit', 'category', 'editor_file'
    ];

    protected $casts = [
        'image_file' => 'array',
        'video_file' => 'array',
        'audio_file' => 'array',
        'editor_file' => 'array',
    ];

    public function user() {
        return $this->belongsTo(User::class, 'user_id');
    }

    public function setImageFileAttribute($value) {
        return $this->attributes['image_file'] = $value;
    }

    public function setVideoFileAttribute($value) {
        return $this->attributes['video_file'] = $value;
    }

    public function setAudioFileAttribute($value) {
        return $this->attributes['audio_file'] = $value;
    }

    public function setEditorFileAttribute($value) {
        return $this->attributes['editor_file'] = $value;
    }

    public function is_star() {
        return $this->hasOne(Star::class, 'entity_id')
            ->where('type', Star::TYPE_SERVICE);
    }

}
